package b3.config
{
	import flash.utils.describeType;
	
	public class BasicConfig
	{
		public function BasicConfig(configXML:XML = null)
		{
			load(configXML);
		}
		
		public function load(config:Object):void
		{
			if (config == null)
				return;
			var instanceInfo:XML = describeType(this);
			var properties:XMLList = instanceInfo..accessor.(@access != "writeonly") + instanceInfo..variable;
			for each (var propertyInfo:XML in properties) {
				var propertyName:String = propertyInfo.@name;
				try
				{
					if (propertyInfo.@type == "Array" && config[propertyName].toString().length > 0)
					{
						this[propertyName] = config[propertyName].toString().split(",");
					}
					else if (propertyInfo.@type == "Boolean")
					{
						this[propertyName] = Boolean(int(config[propertyName]));
					}
					else
					{
						this[propertyName] = config[propertyName];
					}
				}
				catch(e:Error)
				{
					trace(e);
				}
					
			}
		}
	}
}